home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / os2 / cenv2_19.arj / DOSSLAVE.CMD < prev    next >
OS/2 REXX Batch file  |  1994-03-08  |  3KB  |  95 lines

  1. @echo OFF
  2. REM **************************************************************
  3. REM *** DosSlave - This CEnvi tool works with OS2.BAT to allow ***
  4. REM *** ver.1      DOS sessions to perform OS/2 command.  This ***
  5. REM ***            portion runs in the background to service   ***
  6. REM ***            requests from DOS sessions.                 ***
  7. REM **************************************************************
  8.  
  9.  
  10. start "DOS Slave" /N /FS /B CEnvi.exe %0.CMD
  11. WINSET "DOS Slave" HIDE
  12. GOTO CENVI_EXIT
  13.  
  14. #include <FileIO.lib>
  15. #include <NamePipe.lib>
  16.  
  17. PipeName = "\\PIPE\\DOSSLAVE.IN"
  18. PipeHandle;
  19.  
  20. // Open the pipe for reading
  21. rc = DosCreateNPipe(PipeName,PipeHandle,
  22.                     NP_ACCESS_DUPLEX | NP_NOINHERIT,
  23.                     NP_WAIT | NP_TYPE_BYTE | NP_UNLIMITED_INSTANCES | NP_READMODE_BYTE,
  24.                     4000, 4000, 0)
  25. if ( rc )
  26.    printf("Error %d opening named pipe.\a\n",rc), abort();
  27.  
  28. for ( ; ; ) {
  29.    InstructionFile = GetInputFromDOS();
  30.  
  31.    fp = fopen(InstructionFile,"rt");
  32.    if ( NULL == fp )
  33.       printf("Unable to open file \"%s\".\n\a",InstructionFile), abort();
  34.    DoDirectory = fgets(fp);
  35.    DoCommand = fgets(fp);
  36.  
  37.    // get rid of line feed ending DoDirectory and DoCommand
  38.    fclose(fp);
  39.    DoDirectory[strlen(DoDirectory)-1] = 0;
  40.    DoCommand[strlen(DoCommand)-1] = 0;
  41.  
  42.    // determine if piping wanted to be seen
  43.    if ( memicmp("SEE ",DoCommand,4) ) {
  44.       // do it without capturing to a file
  45.       printf("\n%c: & cd %s & %s\n",DoDirectory[0],DoDirectory+2,DoCommand);
  46.       system("%c: & cd %s & %s",DoDirectory[0],DoDirectory+2,DoCommand);
  47.    } else {
  48.       // wants to see results
  49.  
  50.       // output directory is same as input, but with different extension
  51.       strcpy(OutputFile,InstructionFile);
  52.       strcpy(OutputFile + strlen(OutputFile) - 2,"OUT");
  53.  
  54.       // Send cmd.exe command to do directory, then perform command
  55.       printf("\n%c: & cd %s & %s\n",DoDirectory[0],DoDirectory+2,DoCommand+4);
  56.       system("%c: & cd %s & %s > %s",DoDirectory[0],DoDirectory+2,DoCommand+4,OutputFile);
  57.    }
  58.  
  59.    DeleteForever(InstructionFile);
  60. }
  61.  
  62.  
  63. DeleteForever(FileSpec) // delete file with no chance of undeleting
  64. {
  65.    // Delete the input file (without wasting DELDIR space)
  66.    if defined(DELDIR)
  67.       strcpy(SaveDeldir,DELDIR), undefine(DELDIR);
  68.    system("del %s",FileSpec);
  69.    if ( defined(SaveDeldir) )
  70.       strcpy(DELDIR,SaveDeldir), undefine(SaveDeldir);
  71. }
  72.  
  73. GetInputFromDos()
  74. {
  75.    rc = DosConnectNPipe(PipeHandle);
  76.    if ( rc ) {
  77.       printf("Error %d connecting pipe\n",rc);
  78.       abort();
  79.    }
  80.    CommandLength = 0;
  81.    do {
  82.       rc = DosRead(PipeHandle,InChar,1,CharReadCount);
  83.       if ( rc  || 1 != CharReadCount ) {
  84.          printf("\nDosRead error rc = %d, CharReadCount\a\n",rc,CharReadCount);
  85.          abort();
  86.       }
  87.       Input[CommandLength++] = InChar[0];
  88.    } while( '\n' != InChar[0] );
  89.    DosDisconnectNPipe(PipeHandle);
  90.    Input[CommandLength-2] = '\0';
  91.    return( Input );
  92. }
  93.  
  94. :CENVI_EXIT
  95.